package initialize

import (
	"ginTest/global"
	"ginTest/middleware"
	"ginTest/router"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

// 初始化总路由

func Routers() *gin.Engine {
	var Router = gin.Default()
	// Router.Use(middleware.LoadTls())  // 打开就能玩https了
	global.GVA_LOG.Info("use middleware logger")
	// 跨域
	Router.Use(middleware.Cors())
	global.GVA_LOG.Info("use middleware cors")
	Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	global.GVA_LOG.Info("register swagger handler")

	// 方便统一添加路由组前缀 多服务器上线使用
	TestOneGroup := Router.Group("")
	{
		router.InitTestRouter(TestOneGroup) // 注册基础功能路由 不做鉴权
	}

	TestTwoGroup := Router.Group("")
	TestTwoGroup.Use(middleware.StatCost())
	{
		router.InitTestTwoRouter(TestTwoGroup)
	}
	global.GVA_LOG.Info("router register success")
	return Router
}
